//
//  XMMeetEvaluateCell.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/6/23.
//

#import "XMMeetEvaluateCell.h"

@interface XMMeetEvaluateCell ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *itemBtn1;
@property (nonatomic, strong) UIButton *itemBtn2;
@property (nonatomic, strong) UIButton *itemBtn3;

@end

@implementation XMMeetEvaluateCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style
              reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.itemBtn1];
    [self.contentView addSubview:self.itemBtn2];
    [self.contentView addSubview:self.itemBtn3];
    [self item1SelectAction:_itemBtn1];
}

- (void)setContentWithTitle:(NSString *)titleStr
                    itemArr:(NSArray *)itemArr {
    _titleLabel.text = titleStr;
    if (itemArr.count > 0) {
        [_itemBtn1 setTitle:[itemArr firstObject] forState:UIControlStateNormal];
        [_itemBtn1 setTitle:[itemArr firstObject] forState:UIControlStateSelected];
    }
    if (itemArr.count > 1) {
        [_itemBtn2 setTitle:itemArr[1] forState:UIControlStateNormal];
        [_itemBtn2 setTitle:itemArr[1] forState:UIControlStateSelected];
    }
    if (itemArr.count > 2) {
        [_itemBtn3 setTitle:[itemArr lastObject] forState:UIControlStateNormal];
        [_itemBtn3 setTitle:[itemArr lastObject] forState:UIControlStateSelected];
    }
}

- (void)item1SelectAction:(UIButton *)button {
    _itemBtn1.selected = YES;
    _itemBtn2.selected = NO;
    _itemBtn3.selected = NO;
    _itemBtn1.borderWidth = 1;
    _itemBtn2.borderWidth = 0;
    _itemBtn3.borderWidth = 0;
    _itemBtn1.titleLabel.font = KBoldFontSize(14.0);
    _itemBtn2.titleLabel.font = KFontSize(14.0);
    _itemBtn3.titleLabel.font = KFontSize(14.0);
    self.itemSelectBlock ? self.itemSelectBlock(button.titleLabel.text) : nil;
}

- (void)item2SelectAction:(UIButton *)button {
    _itemBtn1.selected = NO;
    _itemBtn2.selected = YES;
    _itemBtn3.selected = NO;
    _itemBtn1.borderWidth = 0;
    _itemBtn2.borderWidth = 1;
    _itemBtn3.borderWidth = 0;
    _itemBtn1.titleLabel.font = KFontSize(14.0);
    _itemBtn2.titleLabel.font = KBoldFontSize(14.0);
    _itemBtn3.titleLabel.font = KFontSize(14.0);
    self.itemSelectBlock ? self.itemSelectBlock(button.titleLabel.text) : nil;
}

- (void)item3SelectAction:(UIButton *)button {
    _itemBtn1.selected = NO;
    _itemBtn2.selected = NO;
    _itemBtn3.selected = YES;
    _itemBtn1.borderWidth = 0;
    _itemBtn2.borderWidth = 0;
    _itemBtn3.borderWidth = 1;
    _itemBtn1.titleLabel.font = KFontSize(14.0);
    _itemBtn2.titleLabel.font = KFontSize(14.0);
    _itemBtn3.titleLabel.font = KBoldFontSize(14.0);
    self.itemSelectBlock ? self.itemSelectBlock(button.titleLabel.text) : nil;
}

#pragma mark - Init
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(16.0), KScaleWidth(16.0), self.width - KScaleWidth(16.0)*2, KScaleWidth(24.0)) font:KFontSize(17.0) textColor:kColorHEX(0x333333)];
    }
    return _titleLabel;
}

- (UIButton *)itemBtn1 {
    if (!_itemBtn1) {
        _itemBtn1 = [UIButton buttonWithType:UIButtonTypeCustom font:KFontSize(14.0) frame:CGRectMake(KScaleWidth(16.0), KScaleWidth(52.0), KScaleWidth(100.0), KScaleWidth(38.0)) title:@"准时到场" selectTitle:@"准时到场" titleColor:kColorHEX(0x666666) selectColor:kColorHEX(0x333333)];
        [_itemBtn1 setRadius:_itemBtn1.height/2 borderColor:kColorHEX(0x979797) borderWidth:0];
        [_itemBtn1 addTarget:self action:@selector(item1SelectAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _itemBtn1;
}

- (UIButton *)itemBtn2 {
    if (!_itemBtn2) {
        _itemBtn2 = [UIButton buttonWithType:UIButtonTypeCustom font:KFontSize(14.0) frame:CGRectMake(KScaleWidth(16.0) + KScaleWidth(100.0) + KScaleWidth(12.0), KScaleWidth(52.0), KScaleWidth(100.0), KScaleWidth(38.0)) title:@"虽迟但到" selectTitle:@"虽迟但到" titleColor:kColorHEX(0x666666) selectColor:kColorHEX(0x333333)];
        [_itemBtn2 setRadius:_itemBtn1.height/2 borderColor:kColorHEX(0x979797) borderWidth:0];
        [_itemBtn2 addTarget:self action:@selector(item2SelectAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _itemBtn2;
}

- (UIButton *)itemBtn3 {
    if (!_itemBtn3) {
        _itemBtn3 = [UIButton buttonWithType:UIButtonTypeCustom font:KFontSize(14.0) frame:CGRectMake(KScaleWidth(16.0) + (KScaleWidth(100.0) + KScaleWidth(12.0))*2, KScaleWidth(52.0), KScaleWidth(100.0), KScaleWidth(38.0)) title:@"没有出现" selectTitle:@"没有出现" titleColor:kColorHEX(0x666666) selectColor:kColorHEX(0x333333)];
        [_itemBtn3 setRadius:_itemBtn1.height/2 borderColor:kColorHEX(0x979797) borderWidth:0];
        [_itemBtn3 addTarget:self action:@selector(item3SelectAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _itemBtn3;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
